package com.ge.modules.sys.controller;

import com.ge.common.utils.DeleteType;
import com.ge.common.utils.PageUtils;
import com.ge.common.utils.Query;
import com.ge.common.utils.R;
import com.ge.modules.entity.TbOrderEntity;
import com.ge.modules.sys.service.SysOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单
 *
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-04-11 17:28:43
 */
@RestController
@RequestMapping("/sys/order")
public class SysOrderController {
    @Autowired
    private SysOrderService sysOrderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sysOrder:list")
    public R list(@RequestParam Map<String, Object> params) {
        params.put("deleteType", DeleteType.NOT_DELETE.getKey());
        //查询列表数据
        Query query = new Query(params);
        List<TbOrderEntity> tbOrderEntityList = sysOrderService.queryList(query);
        int total = sysOrderService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(tbOrderEntityList, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sysOrder:info")
    public R info(@PathVariable("id") Integer id) {
        TbOrderEntity tbOrderEntity = sysOrderService.queryById(id);
        return R.ok().put("order", tbOrderEntity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sysOrder:save")
    public R save(@RequestBody TbOrderEntity tbOrderEntity) {
        sysOrderService.save(tbOrderEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sysOrder:update")
    public R update(@RequestBody TbOrderEntity tbOrderEntity) {
        sysOrderService.update(tbOrderEntity);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sysOrder:delete")
    public R delete(@RequestBody Integer[] ids) {
//        sysOrderService.deleteBatch(ids);
        sysOrderService.updateBatch(ids);
        return R.ok();
    }

}
